﻿<div class="@ClassString" @onclick="OnCheckBoxClickAsync">
    <span class="m_checkbox_box Micon @(Value?"Micon_checked":"Micon_not_checked")"></span><span class="m_checkbox_message">@Title</span>
</div>

@code {
    /// <summary>
    /// 标题
    /// </summary>
    [Parameter]
    public string Title { get; set; }
    /// <summary>
    /// 值
    /// </summary>
    [Parameter]
    public bool Value { get; set; }
    /// <summary>
    /// 值更新
    /// </summary>
    [Parameter]
    public EventCallback<bool> ValueChanged { get; set; }
    /// <summary>
    /// 值更新
    /// </summary>
    [Parameter]
    public EventCallback<bool> OnValueChanged { get; set; }
    /// <summary>
    /// 禁用
    /// </summary>
    [Parameter]
    public bool Disabled{ get; set; }
    /// <summary>
    /// Class字符串
    /// </summary>
    public string ClassString
    {
        get
        {
            var result = "m_checkbox";
            if (Disabled)
            {
                result += " disable";
            }
            return result;
        }
    }
    /// <summary>
    /// 点击CheckBox
    /// </summary>
    /// <param name="eventArgs"></param>
    /// <returns></returns>
    public async Task OnCheckBoxClickAsync(MouseEventArgs eventArgs)
    {
        if (Disabled) return;
        Value = !Value;
        await ValueChanged.InvokeAsync(Value);
        await OnValueChanged.InvokeAsync(Value);
    }
}
